let Home = {
    baseUrl: 'http://81.71.65.4:3003',
    renderOrder(token, oid) {
        // console.log(oid);
        axios.post(this.baseUrl + '/order/detail', { token: token, orderId: oid }).then((res) => {
            let data = res.data.result
            switch (data.orderStatus) {
                case '00':
                    data.orderStatus = '已取消'
                    break;
                case '01':
                    data.orderStatus = '已支付'
                    break;
                case '02':
                    data.orderStatus = '待支付'
                    break;
            }
            // console.log(data);
            document.querySelector('#shopxx b').innerHTML = `<img src="${data.carts[0].imgUrl}">`
            document.querySelector('.text p').innerHTML = `${data.carts[0].masterName}`
            document.querySelector('.text .sp1-1').innerHTML = `${data.carts[0].price /100}`
            document.querySelector('.text .sp2-1').innerHTML = `${data.carts[0].buyNum}`
            document.querySelector('.box1  .b2 .sp').innerHTML = `${data.totalMoney /100}`
            document.querySelector('.box2  .b2 .sp').innerHTML = `${data.expressFee/100}`
            document.querySelector('.box3  .b2 .sp').innerHTML = `${data.totalMoney/100 +data.expressFee/100}`
            document.querySelector('.box .sp').innerHTML = `${data.preOrderId}`
            let times = this.timestampToTime(data.updateTime)
            document.querySelector('.box2 .time').innerHTML = times
            document.querySelector('#dd-nu .box1 .sp').innerHTML = `${data.orderStatus}`
            document.querySelector('#view span').innerHTML = `订单${data.orderStatus}`
        })
    },
    /**
     * 
     * @param {时间戳转换} timestamp 时间戳的值
     * @returns 
     */
     timestampToTime(timestamp) {    
        timestamp = timestamp ? timestamp : null;    
        let date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
            
        let Y = date.getFullYear();
        let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);    
        let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());    
        let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
        let timem = `${Y}-${M}-${D}  ${h}${m}${s}`    
        return timem;  
    }
}

onload = () => {
    let uri = location.href
    let token = localStorage.getItem('token')
    let oid = uri.substring(uri.indexOf("oid=") + 4)
        // console.log(oid);
    Home.renderOrder(token, oid)
}